<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
    <title>React 学习！！</title>
</head>
<body>
<div id="app"></div>
<script src="../bower_components/react/react.min.js"></script>
<script src="../bower_components/react/react-dom.min.js"></script>
<script src="../bower_components/react/browser.min.js"></script>
<script type="text/babel">
    var MessageBox = React.createClass({
        getInitialState: function () {
            return {
                isVisible: true,
                titleMessage: '你好世界（来自state哦）',
            }
        },
        render: function () {
            var styleObj = {
                display: this.state.isVisible ? 'block' : 'none',
            }

            return (
                    <div>
                        <h1 style={styleObj}>{this.state.titleMessage}</h1>
                        <Submessage/>
                    </div>
            )
        }
    });

    var Submessage = React.createClass({
        render: function () {
            return (
                    <h3>写代码很有意思</h3>
            )
        }
    });


    var messageBox = ReactDOM.render(<MessageBox/>,
            document.getElementById('app'),
            function () {
                console.log('渲染完成啦！！');

            }
    )
   //可以用setState进行属性设置
   messageBox.setState({titleMessage:"hahahahaha"});
   //打印state状态属性
   console.log(messageBox.state);
   //如果想用state属性进行状态属性改变的时候，需要用forceUpdate()进行强制更新
   messageBox.state.isVisible = false;
   messageBox.forceUpdate();
   //当然，你还是可以通过setState直接进行属性值的修改操作的
   messageBox.setState({isVisible:true});
</script>
</body>
</html>